---
title: Charmhub | tempo-k8s docs - How to integrate with other charms over `tracing`
description: Setting up tracing integration if you are charming an application that
  is already instrumented for tracing or you plan to configure the workload or the...
url: https://charmhub.io/topics/charmed-tempo-ha/integrate tracing
---

# tempo-k8s docs - How to integrate with other charms over `tracing`

# Setting up tracing integration

if you are charming an application that is already instrumented for tracing or you plan to configure the workload or the charm itself to push traces, you can integrate with [`tempo-coordinator-k8s`](http://charmhub.io/tempo-coordinator-k8s), the single integration entrypoint for [Charmed Tempo HA](https://charmhub.io/topics/charmed-tempo-ha), to send traces to a Tempo endpoint.

Instrumenting your `workload` is not covered under `tempo-k8s`. Some workloads, like `Grafana` are already instrumented for tracing by design. Otherwise, you can use auto-instrumentation libraries to instrument your workload and integrate with `tempo-k8s` as a tracing backend.

For an example of charms that already integrate with `tempo-k8s` to collect traces, see [`loki`](http://charmhub.io/loki-k8s) and [`prometheus`](http://charmhub.io/prometheus-k8s).

## [Add an integration endpoint to `charmcraft.yaml`](https://charmhub.io/topics/charmed-tempo-ha/integrate tracing#p-31329-add-an-integration-endpoint-to-charmcraftyaml)

host and injesters data is communicated over relation data, where the charmed application is the requirer and Tempo charm is the provider.
For consistency across the ecosystem, it is encouraged to name the relation `tracing`.

Edit your charm’s `charmcraft.yaml` to add, under `requires`, the following:

```
requires:
    # any other requirers your charm supports
    tracing:
        interface: tracing
        limit: 1
```

## [Fetch the tracing charm library](https://charmhub.io/topics/charmed-tempo-ha/integrate tracing#p-31329-fetch-the-tracing-charm-library)

`charmcraft fetch-lib charms.tempo_coordinator_k8s.v0.tracing`

The `TracingEndpointRequirer` object enables your charm to easily access Tempo endpoint information exchanged over a `tracing` relation interface.

## [Use `TracingEndpointRequirer`](https://charmhub.io/topics/charmed-tempo-ha/integrate tracing#p-31329-use-tracingendpointrequirer)

If you are intending to send traces with `otlp_http` and `otlp_grpc` tracing protocols:

```
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer

class FooCharm:
    def __init__(self, *args):
        super().__init__(*args, **kwargs)
        ...
        self.tracing = TracingEndpointRequirer(self, protocols=["otlp_http", "otlp_grpc"])
        ...
```

This will ensure that each unit of `Foo` will have access to a Tempo endpoint to push charm traces to once a
relation is established.

For the list of supported `protocols`, see [Tracing Protocols](https://charmhub.io/topics/charmed-tempo-ha/protocols).

## [Access Tempo endpoints](https://charmhub.io/topics/charmed-tempo-ha/integrate tracing#p-31329-access-tempo-endpoints)

After instantiating `TracingEndpointRequirer` with a list of protocols, `tempo-k8s` charm will provide, as part of its databag, a set of Tempo endpoints for the requested protocols that your `workload` & `charm` can use to push traces to.

```
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer

class FooCharm:
   def __init__(self, *args):
       super().__init__(*args, **kwargs)
       ...
       self.tracing = TracingEndpointRequirer(self, protocols=["otlp_http", "otlp_grpc"])
       ...
       # get tempo endpoints
       if self.tracing.is_ready():
           grpc_endpoint = self.tracing.get_endpoint("otlp_grpc")
           http_endpoint = self.tracing.get_endpoint("otlp_http")
```

We recommend that you scale up your tracing provider and relate it to an ingress so that your tracing requests
go through the ingress and get load balanced across all units. Otherwise, if the provider’s leader goes down, your tracing goes down.

## [Configure Juju Topology labels](https://charmhub.io/topics/charmed-tempo-ha/integrate tracing#p-31329-configure-juju-topology-labels)

In order to configure the tracing SDK your workload is using with the correct labels (so that you can always find out which charm a trace was produced by), you’ll first need to do some research.

* If your workload is using Jaeger, you’ll need to set the `JAEGER_TAGS` envvar. (cfr. [upstream docs](https://pkg.go.dev/github.com/jaegertracing/jaeger-client-go/config))
* If your workload is using otel, you’re looking for the `OTEL_RESOURCE_ATTRIBUTES` envvar instead (cfr. [upstream docs](https://opentelemetry.io/docs/specs/otel/resource/sdk/#specifying-resource-information-via-an-environment-variable))

These are just the most common ones, but your workload might be renaming those envvars, masking them, or have a completely different way of configuring the tracing resource attributes. You’ll need to figure out what your workload uses specifically!

Suppose that your workload uses Opentelemetry. Then you should, in your charm, ensure that the pebble environment definition contains the following env:

```
topology = JujuTopology.from_charm(self)
env = {
    "OTEL_RESOURCE_ATTRIBUTES": ",".join("=".join(topology.as_dict().items()))
}
```

[We’re considering](https://github.com/canonical/cos-lib/issues/176) baking into JujuTopology a helper method to do the formatting for you.

Now all the traces the workload is generating will contain the right labels.

---

*Last updated 9 months ago.*

[Help improve this document in the forum](https://discourse.charmhub.io/t/tempo-k8s-docs-how-to-integrate-with-other-charms-over-tracing/14014).
